package Behaviour;

import Model.Car;
import Model.CrossRoads;
import map.CellStatus.CellStatusType;
import map.Map;
import jade.core.Agent;
import jade.core.behaviours.OneShotBehaviour;

public class ChangeCroassRoads extends OneShotBehaviour {
	
	private static final long serialVersionUID = -9172104437104779348L;
	private Map map;

	public ChangeCroassRoads(Agent myAgent, Map map2) {
		super(myAgent);
		this.map = map2;
	}

	@Override
	public void action() {
		for (Car car : map.getCars()) {
			if (!map.getMap()[car.getPosition().x][car.getPosition().y]
					.getStatus().equals(CellStatusType.CROSS)) {
				if (map.getNextNearestCrossRoads(car.getPosition()) != null
						&& map.getPrecNearestCrossRoads(car.getDestination()) != null) {
					if (!map.getNextNearestCrossRoads(car.getPosition())
							.equals(map.getPrecNearestCrossRoads(car
									.getDestination()))){
						CrossRoads a = map.getPrecNearestCrossRoads(car.getPosition());
						CrossRoads b = map.getNextNearestCrossRoads(car.getPosition());
						CrossRoads a1 = map.getPrecNearestCrossRoads(car.getDestination());
						CrossRoads b1 = map.getNextNearestCrossRoads(car.getDestination());
						if(!a.equals(a1) && !b.equals(b1))
							car.updatePathTofollow();
					}
				}
			}
		}

	}

}
